package com.hsteach.web.controller.buildingApply;

import com.hsteach.common.core.controller.BaseController;
import com.hsteach.common.core.domain.AjaxResult;
import com.hsteach.common.core.page.TableDataInfo;
import com.hsteach.common.utils.SecurityUtils;
import com.hsteach.dao.domain.buildingApply.BuildingApply;
import com.hsteach.enums.ApplyTypeEnum;
import com.hsteach.service.buildingApply.BuildingApplyService;
import com.hsteach.web.controller.buildingApply.dto.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 场所申请Controller
 * 
 * @author fanxquer
 * @date 2023-08-25
 */
@Api(value = "场馆申请", tags = "场馆申请")
@RestController
@RequestMapping("/buildingApply")
public class BuildingApplyController extends BaseController
{
    @Autowired
    private BuildingApplyService buildingApplyService;

    /**
     * 查询场所申请列表
     */
    @ApiOperation("查询场所申请列表")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody ListBuildingApplyDto dto)
    {
        return buildingApplyService.listMine(dto, ApplyTypeEnum.BUILDING, SecurityUtils.getAuthInfo().getPersonId());
    }

    /**
     * 查询场所审核列表
     */
    @ApiOperation("查询场所审核列表")
    @PostMapping("/review/list")
    public TableDataInfo listReview(@RequestBody ListReviewDto dto)
    {
        return buildingApplyService.listReview(dto, ApplyTypeEnum.BUILDING);
    }

    /**
     * 审核提交
     */
    @ApiOperation("审核提交")
    @PutMapping("/review")
    public AjaxResult review(@RequestBody ReviewDto dto)
    {
        return toAjax(buildingApplyService.review(dto));
    }

    /**
     * 查询场所时间占用
     */
    @ApiOperation("查询场所时间占用")
    @PostMapping("/holdingTime")
    public TableDataInfo listHoldingTime(@RequestBody ListHoldingTimeDto dto)
    {
        return getDataTable(buildingApplyService.listHoldingTime(dto));
    }

    /**
     * 查询场所时间占用
     */
    @ApiOperation("查询课表时间占用")
    @PostMapping("/timetable")
    public TableDataInfo listTimetable(@RequestBody ListTimetableDto dto)
    {
        return getDataTable(buildingApplyService.listTimetable(dto));
    }

    /**
     * 查询建筑下的场所列表
     */
    @ApiOperation("查询建筑下的场所列表(包含当天时间占用情况)")
    @GetMapping("/rooms")
    public TableDataInfo listRooms(ListRoomsDto dto)
    {
        return getDataTable(buildingApplyService.listRooms(dto.getBuildingId(), dto.getType(), dto.getSearchDate()));
    }

    /**
     * 获取场所申请详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(buildingApplyService.selectBuildingApplyById(id));
    }

    /**
     * 新增场所申请
     */
    @ApiOperation("新增场所申请")
    @PostMapping
    public AjaxResult add(@RequestBody AddBuildingApplyDto dto)
    {
        return toAjax(buildingApplyService.buildingApply(dto, ApplyTypeEnum.BUILDING));
    }

    /**
     * 修改场所申请
     */
    @PutMapping
    public AjaxResult edit(@RequestBody BuildingApply buildingApply)
    {
        return toAjax(buildingApplyService.updateBuildingApply(buildingApply));
    }

    /**
     * 删除场所申请
     */
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(buildingApplyService.deleteBuildingApplyByIds(ids));
    }

    /**
     * 取消场所申请
     */
    @ApiOperation("取消场所申请")
    @PutMapping("/cancel")
    public AjaxResult cancel(@RequestBody CancelApplyDto dto)
    {
        return toAjax(buildingApplyService.cancelApply(dto));
    }
}
